﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
namespace Somnus.IO
{
    public sealed class UsbDrive
    {
        private DriveInfo currentDrive;
        public static UsbDrive[] GetDrives()
        {
            DriveInfo[] allDrives = DriveInfo.GetDrives();
            List<UsbDrive> ui=new List<UsbDrive>();
            foreach (DriveInfo drive in allDrives)
            {
                if (drive.DriveType == DriveType.Removable && drive.IsReady == true)
                {
                    ui.Add(new UsbDrive(drive));
                }
            }
            return ui.ToArray();
            
        }
        private UsbDrive(DriveInfo di)
        {
            currentDrive = di;
        }
        #region Properties
        public long AvailableFreeSpace
        {
            get { return currentDrive.AvailableFreeSpace; }
        }
        public string DriveFormat
        {
            get { return currentDrive.DriveFormat; }
        }
        public string Name
        {
            get { return currentDrive.Name;}
        }
        public DirectoryInfo RootDirectory
        {
            get { return currentDrive.RootDirectory;}
        }
        public long TotalFreeSpace
        {
            get { return currentDrive.TotalFreeSpace;}
        }
        public long TotalSize
        {
            get { return currentDrive.TotalSize;}
        }
        public string VolumeLabel
        {
            get { return currentDrive.VolumeLabel; }
            set { currentDrive.VolumeLabel = value; }
        }
        #endregion
        public override string ToString()
        {
            return currentDrive.ToString();
        }

        public void PerformBehavior(Behavior behavior)
        {
            behavior.DoBehavior(this.currentDrive.RootDirectory.FullName);
        }
    }
}
